# -*- coding: utf-8 -*-
'''
Author: Zhuangyu
Date: 2022-03-30 15:14:42
LastEditTime: 2022-11-26 20:35:00
'''



from __future__ import print_function, division
import numpy as np
from casadi import *


# Contains space, time and soil parameters used to set up
# the 1D and 3D Richards equation models.
# These parameters may be modified to adapt both models
# to a specific field. 

def circular_parameters():
    #Spatial parameters
    Hr=50    #The radius of the field
    Ht=2*np.pi  #The angle of rotation of the pivot
    Ht=2*np.pi  #The angle of rotation of the pivot    
    Hz=0.30  #The depth of the soil
    Nr=6     #Number of nodes in the r-direction
    Nt=40    #Number of nodes in the theta-direction
    Nz=16    #Number of nodes in the z-direction
    dr=Hr/(Nr-1) #distance between nodes in the r-direction
    dt=Ht/Nt     #angle between nodes in the theta-direction
    dz=Hz/(Nz-1) #distance between nodes in the z-direction
    Np=Nt*Nr     #number of nodes in the r-theta plane
    NN=Np*Nz     #total number of nodes
    Nx=NN    #Total number of states
    Nw=Nx    #the dimension of the process noise, w
    Ny=Nx    #The number of measured outputs
    Nv=Ny    #The dimensions of the measurement noise, v
    return Nr,Nt,Nz,dr,dt,dz,Np,NN,Nx,Nw,Ny,Nv,Hz

def time_parameters():
    #Temporal parameters in seconds
    # DeltaT =6*60 
    DeltaT = 60
    Tsim=1*4*6*60*60*6
    # Tsim=1*4*60*60*5
    Nsim = int(Tsim/DeltaT) #Total number of time steps
    return DeltaT,Nsim

def cmatrix_single(Nx):
    CMatrix = np.eye(Nx) #the c-matrix
    return CMatrix

#Soil hydraulic parameters for Loamy soil
def Loam():
  pars={}
  pars['thetaR']=0.078
  pars['thetaS']=0.43
  pars['alpha']=3.6
  pars['n']=1.56
  pars['m']=1-1/pars['n']
  pars['Ks']=0.00000288889
  pars['neta']=0.5
  pars['Ss']=0.00001
  return pars

# Creating the coordinates which identify each node (r,theta,z).
def creating_coordinates(Nz,Nt,Nr):
    coordinates=[]
    for k in range(Nz):
        for j in range(Nt):
            for i in range(Nr):
                y=[i,j,k]
                coordinates.append(y)
    return coordinates




